package com.corex.staticclasses;

import com.classapp.login.LoginBeanMobile;
import com.corex.vinayak.R;
import com.google.gson.Gson;

import android.content.Context;
import android.content.SharedPreferences;

public class PrivateData {
	private LoginBeanMobile loginBeanMobile;
	private SharedPreferences sharedPreferences;
	private Context context;
	private String pin;
	
	public PrivateData(Context context) {
		this.context = context;
	}
	
	public SharedPreferences getSharedPreferences() {
		Context context = this.context;
		sharedPreferences = context.getSharedPreferences(
				context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
		return sharedPreferences;
	}
	public void setSharedPreferences(SharedPreferences sharedPreferences) {
		this.sharedPreferences = sharedPreferences;
	}
	
	public LoginBeanMobile getLoginBeanMobile() {
		String loginBean = getSharedPreferences().getString(context.getString(R.string.shared_pref_login_bean), null);
		Gson gson= new Gson();
		loginBeanMobile = gson.fromJson(loginBean, LoginBeanMobile.class);
		return loginBeanMobile;
	}

	public void setLoginBeanMobile(LoginBeanMobile loginBeanMobile) {
		this.loginBeanMobile = loginBeanMobile;
		SharedPreferences.Editor editor = getSharedPreferences().edit();
		Gson gson= new Gson();
		String loginBeanString = gson.toJson(loginBeanMobile);
		editor.putString(context.getString(R.string.shared_pref_login_bean), loginBeanString);
		editor.commit();
	}

	public Context getContext() {
		return context;
	}
	public void setContext(Context context) {
		this.context = context;
	}

	public String getPin() {
		String loginPin = getSharedPreferences().getString(context.getString(R.string.shared_pref_pin), null);
		return loginPin;
	}

	public void setPin(String pin) {
		SharedPreferences.Editor editor = getSharedPreferences().edit();
		Gson gson= new Gson();
		editor.putString(context.getString(R.string.shared_pref_pin), pin);
		editor.commit();
	}
	
	public void cleanPreference(){
        getSharedPreferences().edit().clear().commit();
    }
}
